<?php
namespace app\api\model;

use app\api\model\Common;

class Asrserver extends Common 
{
    protected $name = 'asr_server';

    //关联模型类
    public function model()
    {
        return $this->belongsTo('Asrmodel','mid')->field('title,id');
    } 
    /**
     * 
     */
    public function getList($condition, $keyword, $page, $limit)
    {
        try{
            $map = [
                'is_delete' => 0
            ];
            if($condition)
            {
                $map[$condition] = ['like','%' . trim($keyword) . '%'];
            }
            $result = $this->with('model')->where($map)->limit($limit)->page($page)->order('id desc')->select();
            $total =  $this->where($map)->count();
            foreach($result as &$value)
            {
                $status = [0=>'未连接',1=>'正常',2=>'异常'];
                $value['statusDetail'] = $status[$value['status']];
            }
            return [
                'list' => $result,
                'total' => $total,
                'totalPage' => $limit != 0 ? ceil($total/$limit) : 0
            ];
        }catch(\Exception $e)
        {
            throw new \Exception($e->getMessage());
        }
    }
}